<?php

namespace App\Services\Cloud\VeTos;

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;

class LaravelVeTosServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        app('filesystem')->extend('tos', function ($app, $config) {
            $adapter = new TosAdapter(
                $config['access_key'],
                $config['secret_key'],
                $config['bucket'],
                $config['domain'],
                $config['region']
            );

            return new FilesystemAdapter(new Filesystem($adapter), $adapter, $config);
        });

        app('filesystem')->extend('tos_public', function ($app, $config) {
            $adapter = new TosAdapter(
                $config['access_key'],
                $config['secret_key'],
                $config['bucket'],
                $config['domain'],
                $config['region']
            );

            return new FilesystemAdapter(new Filesystem($adapter), $adapter, $config);
        });

    }
}
